Xbasic

CHANGE_RECORD Method

Syntax

Validation object as P = <Tbl>.change_record('var')

Arguments

var

A dot variable with the field values from the specified table.

Description

Allows for data to be changed via Xbasic, when using a Form or Browse. Returns a dot variable that is the validation object.

The example below shows how to use the .change_record() method:

'DIM a dot variable with properties that match the fieldnames you want to change
dim r as p
r.firstname = ""
r.company = "alpha"
v = t.change_record(r)
?v.has_errors
= .T.
?v.error.size()
= 2

?v.Format("$(field) = $(error)"+crlf())
= CUSTOMER1->COMPANY = company can't be alpha
CUSTOMER1->LASTNAME = Field is required: LASTNAME

As the example shows, a dot variable is created with properties for all of the fields that you want to enter/change. In the above example, we enter or change the 'firstname' and 'company' fields in the customer table. Once the dot variable has been created, the <Tbl>.change_record() method is called. This method takes as its argument the dot variable with the field values.

The method returns a dot variable. The dot variable has an 'has_errors' property which lets you know if the method succeeded or not. If not, then the errors are returned in an array called 'errors' which is a sub-property of the dot variable. The dot variable that is returned by the .change_record() method is actually an object (the 'validation' object), and it has a .Format() method, which allows you to format the error message into a friendly text or html format ready for display to the user. The format() method can use these placeholders:

$(field)

Placeholder for the fieldname for which the error occurred

$(error)

Placeholder for the plain-text error message

$(errorhtml)

Placeholder for the HTML formatted error message

In the above example, you can see that we call the .Format() method with this argument:

"$(field) = $(error)"+crlf()

The crlf() is necessary because the .Format() method does not put in line breaks between each message. The string "$(field) = $(error)" contains two placeholders which get replaced by each field for which an error occurred and by the corresponding error message.

See Also